/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var works = {};
var common = require('../../utils/commonUtils');
//db转换成model
works.dbConvertModel = function(db){
	var works = {}; 
	if(common.isNotBlank(db.id)) works.id = db.id;	
	if(common.isNotBlank(db.activity_id)) works.activityId = db.activity_id;	
	if(common.isNotBlank(db.member_id)) works.memberId = db.member_id;	
	if(typeof db.title != "undefined") works.title = db.title;
	if(typeof db.img_url != "undefined") works.imgUrl = db.img_url;
	if(typeof db.content != "undefined") works.content = db.content;
	if(typeof db.real_name != "undefined") works.realName = db.real_name;
	if(typeof db.phone != "undefined") works.phone = db.phone;
	if(typeof db.mail != "undefined") works.mail = db.mail;
	if(common.isNotBlank(db.flag)) works.flag = db.flag;	
	if(common.isNotBlank(db.level)) works.level = db.level;	
	if(typeof db.descr != "undefined") works.descr = db.descr;
	if(common.isNotBlank(db.create_time)){
		works.createTime = db.create_time;
		works.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		works.updateTime = db.update_time;
		works.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) works.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) works.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) works.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") works.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") works.bak5 = db.bak5;
	return works;
};

//model转换成db
works.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(common.isNotBlank(obj.activityId)) db.activity_id = obj.activityId;
	if(common.isNotBlank(obj.memberId)) db.member_id = obj.memberId;
	if(typeof obj.title != "undefined") db.title = obj.title;
	if(typeof obj.imgUrl != "undefined") db.img_url = obj.imgUrl;
	if(typeof obj.content != "undefined") db.content = obj.content;
	if(typeof obj.realName != "undefined") db.real_name = obj.realName;
	if(typeof obj.phone != "undefined") db.phone = obj.phone;
	if(typeof obj.mail != "undefined") db.mail = obj.mail;
	if(common.isNotBlank(obj.flag)) db.flag = obj.flag;
	if(common.isNotBlank(obj.level)) db.level = obj.level;
	if(typeof obj.descr != "undefined") db.descr = obj.descr;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

works.initPostReq = function(req){
	var works = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (works.id = req.body.id) : (works.id = req.body.id.trim());
	}
	if(req.body.activityId != undefined){
		(typeof req.body.activityId != 'string') ? (works.activityId = req.body.activityId) : (works.activityId = req.body.activityId.trim());
	}
	if(req.body.memberId != undefined){
		(typeof req.body.memberId != 'string') ? (works.memberId = req.body.memberId) : (works.memberId = req.body.memberId.trim());
	}
	if(req.body.title != undefined){
		(typeof req.body.title != 'string') ? (works.title = req.body.title) : (works.title = req.body.title.trim());
	}
	if(req.body.imgUrl != undefined){
		(typeof req.body.imgUrl != 'string') ? (works.imgUrl = req.body.imgUrl) : (works.imgUrl = req.body.imgUrl.trim());
	}
	if(req.body.content != undefined){
		(typeof req.body.content != 'string') ? (works.content = req.body.content) : (works.content = req.body.content.trim());
	}
	if(req.body.realName != undefined){
		(typeof req.body.realName != 'string') ? (works.realName = req.body.realName) : (works.realName = req.body.realName.trim());
	}
	if(req.body.phone != undefined){
		(typeof req.body.phone != 'string') ? (works.phone = req.body.phone) : (works.phone = req.body.phone.trim());
	}
	if(req.body.mail != undefined){
		(typeof req.body.mail != 'string') ? (works.mail = req.body.mail) : (works.mail = req.body.mail.trim());
	}
	if(req.body.flag != undefined){
		(typeof req.body.flag != 'string') ? (works.flag = req.body.flag) : (works.flag = req.body.flag.trim());
	}
	if(req.body.level != undefined){
		(typeof req.body.level != 'string') ? (works.level = req.body.level) : (works.level = req.body.level.trim());
	}
	if(req.body.descr != undefined){
		(typeof req.body.descr != 'string') ? (works.descr = req.body.descr) : (works.descr = req.body.descr.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (works.createTime = req.body.createTime) : (works.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (works.updateTime = req.body.updateTime) : (works.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (works.bak1 = req.body.bak1) : (works.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (works.bak2 = req.body.bak2) : (works.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (works.bak3 = req.body.bak3) : (works.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (works.bak4 = req.body.bak4) : (works.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (works.bak5 = req.body.bak5) : (works.bak5 = req.body.bak5.trim());
	}
	return works;
};

works.initGetReq = function(req){
	var works = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (works.id = req.query.id) : (works.id = req.query.id.trim());
	}
	if(req.query.activityId != undefined){	
		(typeof req.query.activityId != 'string') ? (works.activityId = req.query.activityId) : (works.activityId = req.query.activityId.trim());
	}
	if(req.query.memberId != undefined){	
		(typeof req.query.memberId != 'string') ? (works.memberId = req.query.memberId) : (works.memberId = req.query.memberId.trim());
	}
	if(req.query.title != undefined){	
		(typeof req.query.title != 'string') ? (works.title = req.query.title) : (works.title = req.query.title.trim());
	}
	if(req.query.imgUrl != undefined){	
		(typeof req.query.imgUrl != 'string') ? (works.imgUrl = req.query.imgUrl) : (works.imgUrl = req.query.imgUrl.trim());
	}
	if(req.query.content != undefined){	
		(typeof req.query.content != 'string') ? (works.content = req.query.content) : (works.content = req.query.content.trim());
	}
	if(req.query.realName != undefined){	
		(typeof req.query.realName != 'string') ? (works.realName = req.query.realName) : (works.realName = req.query.realName.trim());
	}
	if(req.query.phone != undefined){	
		(typeof req.query.phone != 'string') ? (works.phone = req.query.phone) : (works.phone = req.query.phone.trim());
	}
	if(req.query.mail != undefined){	
		(typeof req.query.mail != 'string') ? (works.mail = req.query.mail) : (works.mail = req.query.mail.trim());
	}
	if(req.query.flag != undefined){	
		(typeof req.query.flag != 'string') ? (works.flag = req.query.flag) : (works.flag = req.query.flag.trim());
	}
	if(req.query.level != undefined){	
		(typeof req.query.level != 'string') ? (works.level = req.query.level) : (works.level = req.query.level.trim());
	}
	if(req.query.descr != undefined){	
		(typeof req.query.descr != 'string') ? (works.descr = req.query.descr) : (works.descr = req.query.descr.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (works.createTime = req.query.createTime) : (works.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (works.updateTime = req.query.updateTime) : (works.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (works.bak1 = req.query.bak1) : (works.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (works.bak2 = req.query.bak2) : (works.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (works.bak3 = req.query.bak3) : (works.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (works.bak4 = req.query.bak4) : (works.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (works.bak5 = req.query.bak5) : (works.bak5 = req.query.bak5.trim());
	}
	return works;
};


module.exports = works;
